package com.yoomiito.app.adapter.home.reommend;

import android.content.Context;
import androidx.annotation.NonNull;

import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.yoomiito.app.R;
import com.yoomiito.app.model.bean.HomeVipInfo;
import com.yoomiito.app.utils.L;

import java.util.List;

/**
 * 首页----VIP
 *
 */
public class HomeVipAdapter extends DelegateAdapter.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private LayoutHelper mLayoutHelper;
    private List<HomeVipInfo> mInfos;
    private View.OnClickListener mOnClickListener;
    public HomeVipAdapter(Context context, LayoutHelper layoutHelper, List<HomeVipInfo> infos) {
        mContext = context;
        mLayoutHelper = layoutHelper;
        mInfos = infos;
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mLayoutHelper;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.home_item_iv,parent,false);
        return new ItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
        L.i("首页---adapter---------刷新数据VIP"+mInfos.get(position).isShow());

        itemViewHolder.iv.setVisibility(mInfos.get(position).isShow()?View.VISIBLE:View.GONE);
        itemViewHolder.iv.setOnClickListener(v -> {
            if (mOnClickListener!=null){
                mOnClickListener.onClick(v);
            }
        });
//        itemViewHolder.iv.setVisibility(View.GONE);
//        Glide.with(mContext).load(mInfos.get(position).getVip_img()).into(itemViewHolder.iv);
    }

    @Override
    public int getItemCount() {
        return mInfos.size();
    }

    @Override
    public int getItemViewType(int position) {
        return 2;
    }

    public void setOnClickListener(View.OnClickListener onClickListener) {
        mOnClickListener = onClickListener;
    }

    private class ItemViewHolder extends RecyclerView.ViewHolder{

        private ImageView iv;

        public ItemViewHolder(View itemView) {
            super(itemView);
            iv = itemView.findViewById(R.id.home_item_iv);
        }
    }

    public void setInfos(List<HomeVipInfo> infos) {
        mInfos = infos;
    }
}
